package com.cbs.android.component.weather.weatherinterface.constant;

/**
 * Created by broche on 6/9/16.
 */
public enum WindDirection {
    N(0), EN(1), E(2), ES(3), S(4), WS(5), W(6), WN(7), UNKNOW(99);

    private int value = 0;

    WindDirection(int value) {
        this.value = value;
    }

    public static WindDirection valueOf(int value) {
        switch (value) {
            case 0:
                return N;
            case 1:
                return EN;
            case 2:
                return E;
            case 3:
                return ES;
            case 4:
                return S;
            case 5:
                return WS;
            case 6:
                return W;
            case 7:
                return WN;
            default:
                return UNKNOW;
        }
    }

    public static WindDirection fromAngle(double angle) {
        while (angle < 0) {
            angle += 360;
        }
        while (angle > 360) {
            angle -= 360;
        }
        if (angle < 22.5) {
            return N;
        } else if (angle < 67.5) {
            return EN;
        } else if (angle < 112.5) {
            return E;
        } else if (angle < 157.5) {
            return ES;
        } else if (angle < 202.5) {
            return S;
        } else if (angle < 247.5) {
            return WS;
        } else if (angle < 292.5) {
            return W;
        } else if (angle < 337.5) {
            return WN;
        } else {
            return N;
        }
    }

    public int getValue() {
        return value;
    }
}
